<template>
	<view>
		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input v-model="searchValue" data-name="searchValue" name="searchValue" @focus="onChange" @blur="onSearch"
				 :adjust-position="false" placeholder="请输入区域名称" confirm-type="search"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-green shadow-blur round" @tap="onSearch">搜索</button>
			</view>
		</view>
		<view class="cu-list menu">
			<view class="cu-item" v-for="(area, idx) in areas" :key="idx" :label="area.caAddress">
				<view class="content padding-tb-sm" is-link @click="chooseArea(area)">
					<view>
						<text class="cuIcon-clothesfill text-blue margin-right-xs"></text> {{area.caName}}</view>
					<view class="text-gray text-sm">
						<text class="cuIcon-infofill margin-right-xs"></text> {{area.caAddress}}</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		getAreaId,getAreas
	} from '../../api/area/areaApi.js'
	import {
		isNull,isEmpty
	} from '../../lib/java110/utils/StringUtil.js'
	export default {
		data() {
			return {
				areaCode: '',
				searchValue: '',
				communityName: "",
				areas: ""
			};
		},

		components: {},
		props: {},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			this.vc.onLoad(options);
			let _allAreas = uni.getStorageSync("_allAreas");
			if(isEmpty(_allAreas)){
				this._loadAreas();
			}
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			this._loadAreas();
		},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			onSearch() {
				this._loadAreas();
			},
			onClick() {
				this._loadAreas();
			},
			chooseArea: function(_item) {
				this.vc.setStorageSync('govIndexRefresh','0');
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				uni.setStorageSync("_selectArea",_item);
				prevPage.caName = _item.caName;
				wx.navigateBack({
					delta: 1				,
					});
			},
			_loadAreas: function() {
				let _that = this;
				let dataObj = {
					page: 1,
					row: 20,
					caName: this.searchValue
				};
				getAreas(dataObj)
					.then((_res) => {
							let _area = _res.data;
							_that.areas = _area;
							uni.setStorageSync("_allAreas",_area);
					})
			},
		
		}
	};
</script>
<style>
	@import "./viewAreas.css";
</style>
